<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>流程管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<!-- 查询条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
    <legend>查询条件</legend>
</fieldset>
<form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane" >
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">流程名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="deploymentName"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"><span class="layui-icon layui-icon-search"></span>查询</button>
                    <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
                </div>
            </div>
        </div>
</form>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<table id="processDefinitionList" lay-filter="processDefinitionList"></table>
<table id="deploymentList" lay-filter="deploymentList"></table>
<div>
    <table class="layui-hide" id="workFlowTable" lay-filter="workFlowTable"></table>
    <div id="workFlowToolBar" style="display: none;">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加流程</button>
    </div>

    <div id="deploymentListBar" style="display: none;">
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger" ><span class="layui-icon layui-icon-delete"></span>删除</button>
        <button type="button" lay-event="viewProcessByTaskId" class="layui-btn layui-btn-sm" ><span class="layui-icon layui-icon-edit" ></span>查看流程图</button>
    </div>
</div>

<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 5px" id="addOrUpdateDiv">
    <form class="layui-form" method="post" id="frm">
        <div class="layui-form-item">
            <label class="layui-form-label">流程名称</label>
            <div class="layui-input-block">
                <input type="text" name="deploymentName" lay-verify="required" autocomplete="off"
                       placeholder="请输入流程名称" id="deploymentName" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">流程图文件</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-normal" id="uploadProcess">请选择流程图文件</button>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <button type="button" class="layui-btn" lay-submit="" id="addWorkFlow"  lay-filter="addWorkFlow">提交</button>
            <button type="reset" class="layui-btn layui-btn-warm">重置</button>
        </div>

    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    var tableDeploymentIns;
    var tableProcessDefinitionIns;
    layui.use(['jquery','form','table','layer','upload'],function(){
        var $=layui.jquery;
        var form=layui.form;
        var table=layui.table;
        var layer=layui.layer;
        var upload=layui.upload;

        //选完文件后不自动上传
        upload.render({
            elem: '#uploadProcess'
            ,url: '/workFlow/addWorkFlow'
            ,auto: false
            ,accept:'file'//选择上传文件
            ,acceptMime:'application/zip'//打开文件选择框默认显示压缩文件
            ,exts: 'zip'//校验类型
            ,field:'mf'
            ,data:{
                deploymentName:function(){
                    return $('#deploymentName').val();
                }
            },bindAction: '#addWorkFlow'
            ,done: function(data){
                layer.msg(data.msg);
                //关闭部署的弹出层
                layer.close(mainIndex);
                //刷新table
                tableDeploymentIns.reload();
                tableProcessDefinitionIns.reload();
            }
            ,error:function(){
                layer.msg('部署失败');
                //关闭部署的弹出层
                layer.close(mainIndex);
            }
        });



        //加载流程部署列表
        tableDeploymentIns=table.render({
            elem: '#processDefinitionList'
            ,url:'/workFlow/loadAllDeployment'
            ,toolbar: '#workFlowToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,title: '流程部署列表'
            ,height:'full-350'
            ,limit: 5
            ,cols: [ [
                {field: 'id', title: '部署ID', minWidth:100, align:"center"},
                {field: 'name', title: '部署名称', minWidth:100, align:"center"},
                {field: 'deploymentTime', title: '部署时间', minWidth:100, align:"center"},
                {title: '操作', minWidth:175, templet:'#deploymentListBar',fixed:"right",align:"center"}
            ] ]
        });
        //加载流程定义列表
        tableProcessDefinitionIns=table.render({
            elem: '#deploymentList'
            ,url:'/workFlow/loadAllProcessDefinition'
            ,title: '流程定义列表'
            ,height:'full-380'
            ,limit: 5
            ,cols: [ [
                {field: 'id', title: '流程定义ID', minWidth:100, align:"center"},
                {field: 'name', title: '流程定义名称', minWidth:100, align:"center"},
                {field: 'key', title: '流程定义KEY', minWidth:100, align:"center"},
                {field: 'version', title: '流程定义版本', minWidth:100, align:"center"},
                {field: 'deploymentId', title: '部署ID', minWidth:100, align:"center"},
                {field: 'resourceName', title: '资源文件名[bpmn]', minWidth:100, align:"center"},
                {field: 'diagramResourceName', title: '资源文件名[png]', minWidth:100, align:"center"}
            ] ]
        });

        function view(data){

        }

        //模糊查询
        form.on("submit(doSearch)",function(data){
            tableDeploymentIns.reload({
                where:data.field,
                page:{
                    curr:1
                }
            });
            tableProcessDefinitionIns.reload({
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        });

        //监听工具条的事件
        table.on("toolbar(processDefinitionList)",function(obj){
            switch(obj.event){
                case 'add':
                    openAddLayer();
                    break;
            };
        });

        //监听行工具条的事件
        table.on("tool(processDefinitionList)",function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'delete':
                    deleteWorkFlow(data);
                    break;
                case 'viewProcessByTaskId':
                    viewProcessByTaskId(data);
                    break;
            };
        });

        var mainIndex;
        var url;
        //打开添加的弹出层
        function openAddLayer(){
            mainIndex=layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['600px','250px'],
                title:'添加角色',
                success:function(){
                    $("#frm")[0].reset();
                    url="/role/addRole";
                }
            });
        }

        //查看流程图
        function viewProcessByTaskId(data){
            mainIndex=layer.open({
                type:1,
                content:'<img alt="流程图" src="/workFlow/viewProcessImage?deploymentId='+ data.id+' ">',
                area:['500px','600px'],
                title:'查看'+data.name+'流程图',
                success:function(){
					
                }
            });
        }


        form.on("submit(doSubmit)",function(data){
            $.post(url,data.field,function(res){
                if(res.code==200){
                    tableIns.reload();
                }
                layer.msg(res.msg);
                layer.close(mainIndex);
            })
            return false;
        });
        //删除
        function deleteWorkFlow(data){
            layer.confirm('你确定要删除【'+data.name+'】这条流程吗?', {icon: 3, title:'提示'}, function(index){
                $.post("/workFlow/deleteWorkFlow",{deploymentId :data.id},function(res){
                    if(res.code==200){
                        tableDeploymentIns.reload();
                        tableProcessDefinitionIns.reload();
                    }
                    layer.msg(res.msg);
                })
                layer.close(index);
            });
        }

    });
</script>
</body>
</html>